import 'dart:math';

import 'package:flutter/material.dart';

class SizeConfig {
  static MediaQueryData? _mediaQueryData;

  // 设备宽度
  static double screenWidth = 0;

  // 设备高度
  static double screenHeight = 0;

  // 方向
  static Orientation? orientation;

  // 设计图高度
  static double inputHeight = 812;

// 设计图宽度
  static double inputWidth = 375;
  static EdgeInsets? padding;

// The ratio of actual height to UI design
  static double get scaleWidth => screenWidth / inputWidth;

  static double get scaleHeight => screenHeight / inputHeight;

  static double get scaleText => min(scaleWidth, scaleHeight);

  // 在使用前初始化
  static void init(BuildContext context, double width, double height) {
    inputHeight = height;
    inputWidth = width;
    _mediaQueryData = MediaQuery.of(context);
    screenHeight = _mediaQueryData!.size.height;
    screenWidth = _mediaQueryData!.size.width;
    orientation = _mediaQueryData!.orientation;
    padding = _mediaQueryData!.padding;
  }

  // Get the proportionate width as per screen size
  static double getProportionateScreenWidth(num inputWidth) {
    return inputWidth * SizeConfig.scaleWidth;
  }

  // Get the proportionate height as per screen size
  static double getProportionateScreenHeight(num inputHeight) {
    return inputHeight * SizeConfig.scaleHeight;
  }

  // Get the proportionate size as per font size
  static double getProportionateFontSize(num inputFontSize) {
    return inputFontSize * SizeConfig.scaleText;
  }
}
